<?php 
class DomDateTimePeriodTestCase extends UnitTestCase {
	
	public function test_getNrOfWorkDays() {
		
		$period = new DomDateTimePeriod( '2009-03-01 00:00:00', '2009-03-31 23:59:59');
		$this->assertIdentical( $period->getNrOfWorkDays(), 22 );
		
		$period = new DomDateTimePeriod( '2009-01-15 00:00:00', '2009-03-11 23:59:59');
		$this->assertIdentical( $period->getNrOfWorkDays(), 40 );
		
		$period = new DomDateTimePeriod( '2009-03-27 23:59:59', '2009-04-08 23:59:59');
		$this->assertIdentical( $period->getNrOfWorkDays(), 9 );
		
		$period = new DomDateTimePeriod( '2009-04-15 23:59:59', '2009-04-22 00:00:00');
		$this->assertIdentical( $period->getNrOfWorkDays(), 5 );
		
	}
	
	public function test_getNrOfDays() {
		
		$period = new DomDateTimePeriod( '2009-03-01 00:00:00', '2009-03-31 23:59:59');
		$this->assertIdentical( $period->getNrOfDays(), 30 );
		
		$period = new DomDateTimePeriod( '2009-01-15 00:00:00', '2009-03-11 23:59:59');
		$this->assertIdentical( $period->getNrOfDays(), 55 );
		
		$period = new DomDateTimePeriod( '2009-03-27 23:59:59', '2009-04-08 23:59:59');
		$this->assertIdentical( $period->getNrOfDays(), 11 );
		
		$period = new DomDateTimePeriod( '2006-03-27 23:59:59', '2009-04-08 23:59:59');
		$this->assertIdentical( $period->getNrOfDays(), 1108 );
	}
	
	public function test_getNrOfMonths() {
		
		$period = new DomDateTimePeriod( '2009-03-01 00:00:00', '2009-03-31 23:59:59');
		$this->assertIdentical( $period->getNrOfMonths(), 0 );
		$this->assertIdentical( $period->getNrOfMonths(false), 0 );
		
		$period = new DomDateTimePeriod( '2009-02-28 00:00:00', '2009-03-31 23:59:59');
		$this->assertIdentical( $period->getNrOfMonths(), 1 );
		$this->assertIdentical( $period->getNrOfMonths(false), 1 );
		
		$period = new DomDateTimePeriod( '2009-01-15 00:00:00', '2009-03-11 23:59:59');
		$this->assertIdentical( $period->getNrOfMonths(), 1 );
		$this->assertIdentical( $period->getNrOfMonths(false), 2 );
		
		$period = new DomDateTimePeriod( '2009-03-27 23:59:59', '2009-04-08 23:59:59');
		$this->assertIdentical( $period->getNrOfMonths(), 0 );
		$this->assertIdentical( $period->getNrOfMonths(false), 1 );
		
		$period = new DomDateTimePeriod( '2006-03-27 23:59:59', '2009-04-08 23:59:59');
		$this->assertIdentical( $period->getNrOfMonths(), 36 );
		$this->assertIdentical( $period->getNrOfMonths(false), 37 );
		
		$period = new DomDateTimePeriod( '2000-10-30', '2000-11-30');
		$this->assertIdentical( $period->getNrOfMonths(), 1 );
		$this->assertIdentical( $period->getNrOfMonths(false), 1 );
		
		$period = new DomDateTimePeriod( '2000-10-30', '2000-11-29');
		$this->assertIdentical( $period->getNrOfMonths(), 0 );
		$this->assertIdentical( $period->getNrOfMonths(false), 1 );
	}
	
	public function test_getNrOfYears() {
		
		$period = new DomDateTimePeriod( '2009-03-01 00:00:00', '2008-03-01 00:00:00');
		$this->assertIdentical( $period->getNrOfYears(), 1 );
		
		$period = new DomDateTimePeriod( '2008-03-01 00:00:00', '2009-03-01 00:00:00');
		$this->assertIdentical( $period->getNrOfYears(), 1 );
		
		$period = new DomDateTimePeriod( '2007-02-01 23:59:59', '2009-03-01 00:00:00');
		$this->assertIdentical( $period->getNrOfYears(), 2 );
		
		$period = new DomDateTimePeriod('2009-03-01 00:00:00', '2007-02-01 23:59:59');
		$this->assertIdentical( $period->getNrOfYears(), 2 );
		
		$period = new DomDateTimePeriod( '2007-04-01 23:59:59', '2009-03-01 00:00:00');
		$this->assertIdentical( $period->getNrOfYears(), 1 );
		
		$period = new DomDateTimePeriod( '2009-03-01 00:00:00', '2007-04-01 23:59:59');
		$this->assertIdentical( $period->getNrOfYears(), 1 );
		
		$period = new DomDateTimePeriod( '2008-03-09 23:59:59', '2009-03-07 00:00:00');
		$this->assertIdentical( $period->getNrOfYears(), 0 );
	}
	
	public function test_getNrOfHours() {
		
		$period = new DomDateTimePeriod( '2009-03-01 12:00:00', '2009-03-01 14:00:00');
		$this->assertIdentical( $period->getNrOfHours(), 2 );
		
		$period = new DomDateTimePeriod( '2009-03-01 00:00:00', '2009-03-31 23:59:59');
		$this->assertIdentical( $period->getNrOfHours(), 742 );
		
	}
	
	public function test_getNrOfMinutes() {
		
		$period = new DomDateTimePeriod( '2009-03-01 00:00:00', '2009-03-31 23:59:59');
		$this->assertIdentical( $period->getNrOfMinutes(), 44579 );
		
	}
	
	public function test_getNrOfSeconds() {
		
		$period = new DomDateTimePeriod( '2009-03-01 00:00:00', '2009-03-31 23:59:59');
		$this->assertIdentical( $period->getNrOfSeconds(), 2674799 );
		
	}

	public function test_getMonths() {
		
		$period = new DomDateTimePeriod('2009-10-10','2009-12-09');
		
		$months = $period->getMonths();		
		$this->assertIdentical( $months[0]->getStart()->date(), '2009-10-01 00:00:00');
		$this->assertIdentical( $months[0]->getEnd()->date(), '2009-10-31 23:59:59');
		$this->assertIdentical( $months[1]->getStart()->date(), '2009-11-01 00:00:00');
		$this->assertIdentical( $months[1]->getEnd()->date(), '2009-11-30 23:59:59');
	}
	
	public function test_getDays() {
		
		$period = new DomDateTimePeriod('2009-10-10','2009-10-12');
		
		$days = $period->getDays();	
		$this->assertIdentical( $days[0]->getStart()->date(), '2009-10-10 00:00:00');
		$this->assertIdentical( $days[0]->getEnd()->date(), '2009-10-10 23:59:59');
		$this->assertIdentical( $days[1]->getStart()->date(), '2009-10-11 00:00:00');
		$this->assertIdentical( $days[1]->getEnd()->date(), '2009-10-11 23:59:59');
		$this->assertIdentical( $days[2]->getStart()->date(), '2009-10-12 00:00:00');
		$this->assertIdentical( $days[2]->getEnd()->date(), '2009-10-12 23:59:59');
	}

}
?>